<?php
/**
 * 部门操作控制器
 */
namespace app\api\controller;

use app\common\controller\Common;

class Department extends Base
{
    protected $model;
    public  function  __construct()
    {
        parent::_initialize();
        $this->model = Model('Department');
    }

    /**
     * 新群组创建
     */
    public function create()
    {
        //
        $ids = input('param.ids');
        $title = input('param.title');
        if(!$title)
        {
            return resultArray(['error' => '群组名不能为空']);
        }
        $param = [
            'title' => $title,
            'pid' => 0,
            'create_time' => time(),
            'update_time' => time()
        ];
        //群组model
        $result = $this->model->createDate($param, $ids ? explode(',', $ids) : []);
        if(!$result){
            return resultArray(['error' => $this->model->getError()]);
        }
        return resultArray(['data' => '']);
    }

    /**
     * 新群组列表
     */
    public function list(){
        $result = $this->model->getList(false,false,false,false);
        if(!$result)
        {

        }
        return resultArray(['data' => $result]);
    }

    /**
     * 新群组修改
     */
    public function edit(){
        $result = $this->model->updateDataById($this->param['dptid'], $this->param);
        if(!$result)
        {
            return resultArray(['error' => $this->model->getError()]);
        }
        return resultArray(['data' => '']);
    }
    
    /**
     *  部门删除
     *  参数 
     *  dptid 部门id
     */
    public function delete()
    {
        $result = $this->model->delDataById($this->param['dptid']);
        if (!$result) {
            return resultArray(['error' => $this->model->getError()]);
        }
        return resultArray(['data' => '']);
    }

    /**
     *  部门详情
     */
    public function detail(){
        $result = $this->model->getDataDetail($this->param['dptid']);
        if(!$result){
            return resultArray(['error' => $this->model->getError()]);
        }
        return resultArray(['data' => $result]);
    }
}
